<template>
  <div>
    home page789789798
    <button @click="downLoad">下载</button>
  </div>
</template>
  <script setup >
import { onMounted } from "vue";
import axios from "axios";
import { saveAs } from "file-saver";

import { downLoadApi } from "@/api/user";
const downLoad = async () => {
  axios.get("/api/download", { responseType: "blob" }).then((res) => {
    console.log(res.data);
    const contentDisposition = res.headers["content-disposition"];
    let fileName = "";
    if (contentDisposition) {
      const fileNameMatch = contentDisposition.match(
        /filename\*?=["']?(?:UTF-\d['"]*)?([^;\n]*)["']?/i
      );
      fileName = fileNameMatch ? fileNameMatch[1] : fileName;
      fileName = decodeURIComponent(fileName.trim());
    }
    console.log("解析出的文件名:", fileName);
    saveAs(new Blob([res.data]), fileName);
  });
};

onMounted(() => {});
</script>
  <style lang='less' scoped></style>